﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：审计预警规则
 */

var acceptClick;
var keyValue = '';
var bootstrap = function ($, learun) {
    "use strict";
    var selectedRow = learun.frameTab.currentIframe().selectedRow;
    var page = {
        init: function () {
            page.bind();
            page.initData();
            if (!!selectedRow) {
                $('#code').attr('readonly', 'readonly');
            }
        },
        bind: function () {

        },
        initData: function () {
            if (!!selectedRow) {
                keyValue = selectedRow.id;

                $.lrSetForm(config.base_server() + 'auditmodelrules/findByModelId?modelId=' + keyValue, function (data) {
                    if (data != null) {
                        $("#modelId").val(data[0].modelId);
                        $("#modelName").val(data[0].modelName);
                        var html = " <span style=\"color: red;text-decoration: underline;margin-top: 70px;margin-left: 30px;font-weight: bold;\">参数设置</span>";
                        for (let i = 0; i < data.length; i++) {
                            html += '<div class="col-xs-12 lr-form-item">';
                            html += '  <div class="lr-form-item-title">' + data[i].confName + '<font face="宋体">*</font></div>';
                            html += '      <input id="' + data[i].confKey + '" type="text" value="' + data[i].confValue + '" class="form-control" isvalid="yes" checkexpession="NotNull">';
                            html += '  <div class="tip"></div>';
                            html += '</div>';
                            html += '<div class="lr-form-item-text">';
                            html += data[i].confDescription;
                            html += '</div>';
                        }
                        $("#div_config").append(html);
                    }
                });
            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        var postData = $('#form').lrGetFormData(keyValue);
        $.lrSaveForm(config.base_server() + 'auditmodelrules/saveOrUpdate?access_token=' + config.getToken().access_token + '&keyValue=' + keyValue, JSON.stringify(postData), function (res) {
            // 保存成功后才回调
            if (!!callBack) {
                callBack();
            }
        });
    };
    page.init();
}
